package com.abigdreamer.swing.app.skin;

import com.abigdreamer.swing.app.SwingUtil;
import java.awt.Image;
import javax.swing.ImageIcon;

public class Skin
{
  private String name;
  private boolean selected;
  private Boolean isDefault;
  private SkinUnit unit;
  
  public Skin(String name)
  {
    this.name = name;
  }
  
  public Image getImage()
  {
    return isDefault() ? null : new ImageIcon(SkinConst.SKIN_DIR + 
      SkinConst.FILE_SEP + this.name + SkinConst.FILE_SEP + 
      "normal.png").getImage();
  }
  
  public Image getBlurImage()
  {
    return isDefault() ? null : new ImageIcon(SkinConst.SKIN_DIR + 
      SkinConst.FILE_SEP + this.name + SkinConst.FILE_SEP + 
      "blur.png").getImage();
  }
  
  public Image getPreviewImage()
  {
    return isDefault() ? SwingUtil.getImage("default_skin_preview.png") : 
      new ImageIcon(SkinConst.SKIN_DIR + SkinConst.FILE_SEP + this.name + 
      SkinConst.FILE_SEP + "preview.png")
      .getImage();
  }
  
  public String getName()
  {
    return this.name;
  }
  
  public boolean isSelected()
  {
    return this.selected;
  }
  
  public void setSelected(boolean selected)
  {
    this.selected = selected;
    if (this.unit != null) {
      this.unit.repaint();
    }
  }
  
  public SkinUnit getUnit()
  {
    return this.unit;
  }
  
  public void setUnit(SkinUnit unit)
  {
    this.unit = unit;
  }
  
  public boolean isDefault()
  {
    if (this.isDefault == null) {
      this.isDefault = Boolean.valueOf(this.name.equals("默认皮肤"));
    }
    return this.isDefault.booleanValue();
  }
  
  public String toString()
  {
    return this.name;
  }
}
